package ttp.service;

import java.util.HashMap;

import ttp.dao.TtpDAO;
import ttp.to.ChemicalTO;
import ttp.to.DryingTO;
import ttp.utilities.Utilities;

public class DryingService {
	private TtpDAO dao;

	public DryingService(TtpDAO dao) {
		super();
		this.dao = dao;
	}

	public HashMap run() throws Exception{
		long start_time = System.currentTimeMillis();
		DryingTO dto = new DryingTO();
		ChemicalTO cmto = dao.selectChemicalByNo(0);
		if(cmto!=null){
			int dryingNo = dao.sequenceDrying();
			String enterPrise = cmto.getEnterPrise();
			String treeType = cmto.getTreeType();
			String treeGrade = cmto.getTreeGrade();
			int pulpWeight = cmto.getPulpWeight();
			int paperWeight = pulpWeight - (pulpWeight/10);
			String productDate = Utilities.getNow();
			int dryingCheck = (int) (Math.random()*100)+1;
			if(dryingCheck==100){
				dryingCheck = 1;
			}else{
				dryingCheck = 0;
			}
			dto = new DryingTO(dryingNo, enterPrise, treeType, treeGrade, paperWeight, productDate, dryingCheck, 0, 0);
			dao.insertDrying(dto);
			dao.updateChemical(cmto.getChemicalNo());
			Thread.sleep(5500);
		}else{
			Thread.sleep(5500);
			dto = null;
		}
		long end_time = System.currentTimeMillis();
		System.out.println("Drying 처리시간: " + String.format("%,d msec", end_time - start_time));
		HashMap map = new HashMap();
		map.put("dto", dto);
		map.put("time", String.format("%,d msec", end_time - start_time));
		return map;
	}
}


